define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/withdrawlog/index' + location.search,
                    add_url: 'user/withdrawlog/add',
                    edit_url: 'user/withdrawlog/edit',
                    // del_url: 'user/withdrawlog/del',
                    multi_url: 'user/withdrawlog/multi',
                    import_url: 'user/withdrawlog/import',
                    table: 'user_withdrawlog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'user.is_channel', title: __('是否经销商'), searchList: { "0": __('否'), "1": __('是') }, formatter: Table.api.formatter.label },
                        // {field: 'user_id', title: __('User_id')},
                        {
                            field: 'money', title: __('到账金额'), operate: false, formatter: function (row, col) {
                                return (Number(col.money) - Number(col.tax_rate)).toFixed(2);
                            }
                        },
                        { field: 'tax_rate', title: __('手续费'), operate: false },

                        { field: 'status', title: __('Status'), searchList: { "0": __('Status 0'), "1": __('Status 1'), "2": __('Status 2') }, formatter: Table.api.formatter.status },
                        { field: 'msg', title: __('Msg'), operate: 'LIKE' },
                        { field: 'uptime', title: __('Uptime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'bank.cardholder', title: __('True_name'), operate: 'LIKE' },
                        { field: 'bank.account', title: __('Cardno'), operate: 'LIKE' },
                        { field: 'bank.bank_name', title: __('Bank'), operate: 'LIKE' },
                        { field: 'bank.outlets', title: __('开户支行'), operate: 'LIKE' },
                        { field: 'type', title: __('提现方式'), searchList: { "1": __('线下提现'), "2": __('用友提现') }, formatter: Table.api.formatter.label },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        // { field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'user.new_nickname', title: __('Nickname'), operate:false },
                        { field: 'user.nickname', title: __('Nickname'), visible: false, operate: 'LIKE' },
                        { field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'user/withdrawlog/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'user/withdrawlog/restore',
                                    refresh: true
                                }

                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
